namespace SimpleWebServices.Web.UI.Html.Elements
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Xml.Serialization;

    [XmlRoot("input")]
    public class HiddenInput : Input, IXmlSerializable
    {
        public HiddenInput()
        {
        }

        public HiddenInput(Name id, string value)
            : this(id, id, value)
        {
        }

        [SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "There are no unintended consequences.")]
        public HiddenInput(Name id, Name name, string value)
        {
            this.Id = id;
            this.Name = name;
            this.Value = value;
        }

        public HiddenInput(Name id)
            : base(id)
        {
        }

        public override string Type
        {
            get
            {
                return "hidden";
            }
        }

        public override IElement Deserialize(string name, string type, string xml)
        {
            IElement result = null;

            if ("input".Equals(name, StringComparison.OrdinalIgnoreCase) && this.Type.Equals(type, StringComparison.OrdinalIgnoreCase))
            {
                result = xml.Deserialize<HiddenInput>();
            }

            return result;
        }
    }
}